package edu.hunau.recommend.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.hunau.recommend.advice.AdminPermission;
import edu.hunau.recommend.pojo.Category;
import edu.hunau.recommend.request.PageQuery;
import edu.hunau.recommend.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.expression.Lists;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author name
 * @creater 2022-09-19-15:44
 */
@Controller
@RequestMapping("/admin/category")
public class CategoryManagerController {

    @Resource
    private CategoryService categoryService;

    @RequestMapping("/index")
    @AdminPermission
    public ModelAndView index(PageQuery pageQuery){
        //设置分页起始页和页面大小
        PageHelper.startPage(pageQuery.getPage(), pageQuery.getSize());
        List<Category> lists = categoryService.selectAll();
        PageInfo<Category> pageInfo = new PageInfo<>(lists);


        ModelAndView mv = new ModelAndView("/admin/category/index.html");
        mv.addObject("CONTROLLER_NAME","category");
        mv.addObject("ACTION_NAME","index");
        mv.addObject("data",pageInfo);

        return mv;
    }
}
